<template lang="html">
  <div class="container">
    <header>
      <v-navbar></v-navbar>
      <div class="navbar-footer">
        <div class="navbar-footer-content">
          <h2>
            <a href="#">西闻</a>
            <span>人文和科技的交汇</span>
          </h2>
        </div>
      </div>
      <div class="carousel">
        <div class="wrapper">
          <v-carousel class="carousel1" :currentItemIndex="currentIndex">
            <v-carousel-item v-for="(item,index) in data" :key="item.id">
              <h1>{{item.title}}</h1>
              <p>{{item.text}}</p>
              <div class="read-button">
                <span>阅读原文</span>
              </div>
            </v-carousel-item>
          </v-carousel>
          <v-carousel class="carousel2" @roll="handleRoll" :currentItemIndex="currentIndex" show-controler :interval=10000>
            <v-carousel-item v-for="(item,index) in data" :key="item.id">
              <img :src="item.image1">
            </v-carousel-item>
          </v-carousel>
          <v-carousel class="carousel3" :currentItemIndex="nextItemIndex">
            <v-carousel-item v-for="(item,index) in data" :key="item.id">
              <h3>{{item.title}}</h3>
              <div class="img">
                <img :src="item.image2">
              </div>
            </v-carousel-item>
          </v-carousel>
        </div>
        <div class="sidebar">
          <div class="sidebar1">西城头条</div>
          <div class="sidebar2">今日必读资讯</div>
        </div>
      </div>
    </header>
    <section>
      <div class="section-container">
        <div class="classify" ref="classify">
          <ul>
            <li>
              <a href="#">全部</a>
              <div class="border"></div>
            </li>
            <li>
              <a href="#">快讯</a>
              <div class="border"></div>
            </li>
            <li>
              <a href="#">图说</a>
              <div class="border"></div>
            </li>
            <li>
              <a href="#">言论</a>
              <div class="border"></div>
            </li>
            <li>
              <a href="#">产品</a>
              <div class="border"></div>
            </li>
          </ul>
        </div>
        <div class="masonry">
          <v-card
          class="card"
          v-for="(item,index) in masonry"
          :image="item.image"
          :avatar="item.avatar"
          :key="item.id"
          :title="item.title"
          :paragraph="item.paragraph"
          :author="item.author"
          :time="item.time"
          :upvote="item.upvote"
          :classify="item.classify"
          @loaded=adjustHeight
          ref="test"
          ></v-card>
        </div>
      </div>
      <div class="more">
        <span>加载更多</span>619
      </div>
    </section>
    <footer>
      <div class="footer-content">
        <div class="footer-left">
          <div class="logo">
            <i class="material-icons">terrain</i>
          </div>
          <div class="footer-icon">
            <div class="icon"><i class="material-icons">terrain</i></div>
            <div class="icon"><i class="material-icons">terrain</i></div>
            <div class="icon"><i class="material-icons">terrain</i></div>
          </div>
          <span>© 2010 - 2018 DGtle.com</span>
          <span>CC BY-NC-SA 4.0</span>
          <span>粤 ICP 备 13000416 号-1</span>
        </div>
        <div class="footer-right">

        </div>
      </div>
    </footer>
  </div>
</template>
<script>

import data from './data'
import masonry from './masonry'
import {vDropdownUl, vDropdownLi, vNavbar, vCarousel, vCarouselItem, vCard} from '~/components/common'

export default {

  components: {
    vCard,
    vNavbar,
    vCarousel,
    vDropdownUl,
    vDropdownLi,
    vCarouselItem
  },
  data () {
    return {
      data: data,
      column: 4,
      timer: null,
      loadImage: 0,
      currentIndex: 0,
      masonry: masonry,
      BUTTON_VISIBLE: false
    }
  },
  methods: {
    handleRoll (val) {
      this.currentIndex = val
    },
    adjustHeight () {
      console.log(this.$refs.test[0].$el.offsetHeight)
      // this.loadImage++
      // if (this.loadImage === this.masonry.length) {
      //   let cards = document.getElementsByClassName('card')
      //   for (let i = 0; i < cards.length; i++) {
      //     if (i > 3) {
      //       cards[i].style.top = (cards[i - 4].getBoundingClientRect().bottom - cards[i].getBoundingClientRect().top + 20) + 'px'
      //     }
      //   }
      // }
    }
  },
  computed: {
    nextItemIndex () {
      if (this.currentIndex === this.data.length - 1) {
        return 0
      }
      return this.currentIndex + 1
    }
  }
}
</script>

<style lang="scss" scoped>

@mixin pull-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

* {
  box-sizing: border-box;
}

.container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #fff;

  header {

    .navbar-footer {
      color: #333;
      height: 80px;
      margin-top: 60px;
      background-color: #fff;
      box-shadow: 0 15px 15px rgba(15, 37, 64, 0.1);

      .navbar-footer-content {
        width: 1200px;
        margin: 0 auto;

        h2 {
          position: relative;
          text-align: left;
          display: inline-block;
          a {
            color: #424E65;
            font-weight: 500;
            text-decoration: none;
            height: 80px;
            line-height: 80px;
            display: inline-block;
            vertical-align: middle;
            margin-right: 20px;
          }

          a:before {
            content: '';
            position: absolute;
            left: 58px;
            top: 30px;
            width: 1px;
            height: 20px;
            background-color: #e5e5e5;
            z-index: 0;
          }

          span {
            font-weight: 500;
            font-size: 16px;
            height: 80px;
            line-height: 80px;
            display: inline-block;
            vertical-align: middle;
            color: #666;
          }
        }
      }
    }
    .carousel {
      @include pull-center;
      height: 660px;
      padding: 60px 0px;
      position: relative;
      display: flex;
      align-items: center;
      z-index: 0;
      .wrapper {
        position: relative;
        width: 1200px;
        height: 420px;
        margin: 0;
        padding: 0;
        display: flex;
        align-items: flex-end;
        justify-content: space-between;
        z-index: 0;
        &:after {
          top: -50px;
          right: -20px;
          position: absolute;
          content: '';
          width: 600px;
          height: 540px;
          background-color: #fafafa;
          z-index: 0;
        }

        .carousel1 {
          width: 360px;
          height: 430px;
          letter-spacing: 1px;
          h1 {
            color: #333;
            font-size: 30px;
            font-weight: 700;
            letter-spacing: 1px;
          }
          p {
            margin: 33px 0px 20px 0px;
            color: #999;
          }
          .read-button {
            display: flex;
            align-items: center;
            justify-content: center;

            width: 100px;
            height: 40px;
            border-radius: 20px;
            background-color: #f0f0f0;
            transition: background-color 300ms;
            &:hover {
              background-color: #ddd;
            }
            span {
              font-size: 14px;
              color: #666;
            }
          }
        }

        .carousel2 {
          width: 600px;
          height: 400px;
          position: relative;
          z-index: 1;
          .img {
            width: 200px;
            height: 200px;
            img {
              width: 100%;
              height: 100%;
              object-fit: cover;
            }
          }
        }

        .carousel3 {
          position: relative;
          z-index: 1;
          top: 3px;
          width: 200px;
          height: 276px;
          background-color: #fafafa;
          h3 {
            display: -webkit-box;
            width: 180px;
            height: 53px;
            font-weight: 400;
            line-height: 1.5;
            overflow : hidden;
            margin-bottom: 20px;
            padding-right: 10px;

            -webkit-line-clamp: 2;
            text-overflow: ellipsis;
            -webkit-box-orient: vertical;
          }
          img {

            object-fit: cover;
          }
        }
      }
      .sidebar {
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        height: 420px;
        .sidebar1 {
          width: 24px;
          color: #999;
          height: 112px;
          font-size: 14px;
          line-height: 26px;
          text-align: center;
          position: relative;
          margin-left: 24px;
        }
        .sidebar2 {
          width: 24px;
          height: 168px;
          color: #999;
          font-size: 24px;
          line-height: 28px;
          text-align: center;
          margin-left: 24px;
        }
      }
    }
  }

  section {
    width: 100%;
    background-color: #fafafa;
    position: relative;
    .section-container {
      width: 1290px;
      margin: 0 auto;
      position: relative;

      .classify {
        width: 100%;
        height: 78px;
        padding-top: 20px;
        margin: 0px 0px 30px 0px;
        ul {
          display: flex;
          justify-content: center;
          padding: 0;
          height: 100%;
          li {
            position: relative;
            height: 58px;
            list-style: none;
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 0 20px;
            padding: 0 10px;
            cursor: pointer;

            a {
              color: #999;
              font-size: 18px;
              text-decoration: none;
              transition: color 300ms;
            }

            .border {
              position: absolute;
              bottom: 0;
              width: 0%;
              height: 2px;
              background-color: #333;
              transition: width 300ms;
            }

            &:hover {
              a {
                color: #333;
                transition: color 300ms;
              }
              .border {
                width: 100%;
                transition: width 300ms;
              }
            }
          }
        }
      }

      .masonry {
        position: relative;

        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        max-width: 1290px;

        .card {
          position: relative;
          top: 0;
        }
      }
    }
    .more {
      margin: 0 auto;
      width: 140px;
      height: 40px;
      visibility: hidden;
      margin: 0 auto;
      position: relative;

      @include pull-center;
      span {
        position: absolute;
        bottom: 100px;

        width: 140px;
        height: 40px;
        color: #999;
        font-size: 14px;
        cursor: pointer;
        font-weight: 400;
        line-height: 40px;
        text-align: center;
        visibility: visible;
        border-radius: 100px;
        border: 1px solid #ccc;
        background-color: transparent;
        transition: all 500ms;

        &:hover {
          color: #fff;
          border: none;
          transform: scale(1.1);
          transition: all 500ms;
          background-color: #4790E5;
          /* filter: brightness(1.05) contrast(1.05); */
        }
      }
    }
  }

  footer {
    display: flex;
    justify-content: center;
    height: 330px;
    padding-top: 60px;
    background-color: #282D36;
    .footer-content {
      width: 1200px;
      height: 172px;
      display: flex;
      justify-content: space-around;
      .footer-left {
        width: 150px;
        height: 171px;
        background-color: #a44;
        .logo {
          width: 150px;
          height: 53px;
          background-color: #44a;
          i {
            font-size: 48px;
          }
        }
        .footer-icon {
          width: 150px;
          height: 40px;
          display: flex;
          margin-top: 20px;
          justify-content: space-around;
          .icon {
            width: 40px;
            height: 40px;
            background-color: #567;
            i {
              width: 100%;
              height: 100%;
              color: #ddd;
              font-size: 36px;
              text-align: center;
            }
          }
        }
        span {
          color: #666;
          font-size: 12px;
        }
      }
      .footer-right {
        width: 600px;
        height: 164px;
        background-color: #5b5;
      }
    }
  }
}
</style>
